import {http} from "@/service/http";
import {User} from '@/types/user'
import {Page, PageQuery} from "@/types/response";

const prefix = '/User'


/**
 * delete
 * @param id id
 * @returns
 */
export const deleteUserByUserId = (id: number) => {
  return http({
    method: 'Delete',
    url: `${prefix}/Delete`,
    params: {
      id
    }
  })
}


/**
 * Page
 * @param page page 1
 * @returns PageList
 */
export const getUserByPage = (page:PageQuery) => {
  return http<Page<User[]>>({
    method: 'GET',
    url: `${prefix}/Get`,
    params: {
      ...page
    }
  })
}


/**
 * getUserInfo
 * @param id userId
 * @returns UserInfo
 */
export const getUserById = (id: number) => {
  return http<User>({
    method: 'Get',
    url: `${prefix}/Get/${id}`,
  })
}


/**
 * 通过token获取User
 * @param token token
 * @returns User
 */
export const getUserInfoByToken = (token: string) => {
  return http<User>({
    method: 'Get',
    url: `${prefix}/GetInfoByToken`,
    params: {
      token
    }
  })
}


/**
 * 添加User
 * @param user User
 * @returns
 */
export const createUser = (user: User) => {
  return http({
    method: 'POST',
    url: `${prefix}/Post`,
    data: user
  })
}


/**
 * 修改User
 * @param user
 * @returns
 */
export const updateUser = (user: User) => {
  return http({
    method: 'Put',
    url: `${prefix}/Put`,
    data: user
  })
}

